<script type="text/javascript">
function empty_cart(){

	if (confirm('vous voulez vider le panier?')) {
		
		$.post("<?=site_url('cart/empty_cart')?>", function(data) {
			
			window.location.reload();
			});
		
	   }
	}

function choose_com(){
	$('.community_list').fadeIn(100);
}
function close_choose_com (){
	$('.community_list').hide();
	$('option:first','#com').attr('selected','selected');
	$('.error').html('');
}
function delivery_validation(){
	$arrow = $('.delivery_arrow');
	$com_id = $('#com').val();
	$com_name = $('option:selected','#com').text();
	$com_text =$('option:selected','#com').text();
	$com_code = $('option:selected','#com').attr('com_code');
	$com_limit =  $('option:selected','#com').attr('limit');
	$current_total = '<?=number_format($this->cart->total()*(1-$this->discount_delivery[0]->discount_val),1,'.','')?>';
	$different = ($com_limit-$current_total).toFixed(1);
	if($com_id == 'null'){
			$arrow.show();
		}else{
			$arrow.css('display','none');
			if($current_total*1 < $com_limit*1)
			{
				$('#com_name').attr('value',$com_name);
				$('.error').html('<div class="txt_highlight">livraison à domicile à partir de '+$com_limit+'€ pour '+$com_text+'<br><br><div>Vous voulez ajouter '+$different+' € pour cette commande?</div><input type="button" value="Oui" onclick="send_delivery_form('+$different+')"> ou <input type="button" value="Non" onclick="close_choose_com()"><hr>' ) ;
			}else{
				$('#com_name').attr('value',$com_name);
				$('#delivery_form').submit();
			}
			}
	
}
function send_delivery_form($d){
	$('#extra').attr('value',$d); 
	$('#delivery_form').submit();
}
</script>
<div id="container">
<div id="sidebar">
	<div class="logo"><a href="<?=site_url()?>"><img src="<?=base_url()?>resources/imgs/logo.png" alt="" width="200"></a><p class="sub-title">Traiteur Chinois</p></div>
		<hr>
		<h3>Sauce supplémentaire</h3>
		
		<?php foreach ($sauces as $s):?>
		<div class="sauce_item">
	
		<small style="text-align:right;"><form action="<?=site_url('cart/insert')?>" method="post">
		<?=$s->product_name?> <?=$s->product_price?>€ X
		<select name="qty">
		<?php for($k=1;$k<5;$k++){?>
		<option value="<?=$k?>"><?=$k?></option>
		<?php }?>
		</select>
		<input type="hidden" name="url" value="<?=current_url()?>">
		<input type="hidden" name="id" value="<?=$s->id?>">
		<input type="hidden" name="price" value="<?=$s->product_price?>">
		<input type="hidden" name="name" value="<?=$s->product_name?>">
		<input type="hidden" name="product_num" value="<?=$s->product_num?>">
		<input type="submit" value="ajouter" class="button">
		</form>
		</small>
		</div>
		<?php endforeach;?>
		<?php if($this->discount || $this->discount_delivery){?>
		<h3>Promo!</h3>
		<?php if($this->discount){?>
	<div class="promo">
	A partir du <?=date('d M. Y',strtotime($this->discount[0]->discount_start))?> jusqu'au <?=date('d M. Y',strtotime($this->discount[0]->discount_end))?>, Une Réduction de <?=$this->discount[0]->discount_val*100?>% pour toutes les commandes paiement par espèces !!!
	</div>
	<?php }?>
	<?php if($this->discount_delivery){?>
	<div class="promo">
	A partir du <?=date('d M. Y',strtotime($this->discount_delivery[0]->discount_start))?> jusqu'au <?=date('d M. Y',strtotime($this->discount_delivery[0]->discount_end))?>,  Pour les commandes de livraison, Une Réduction de <?=$this->discount_delivery[0]->discount_val*100?>% 
	pour les communes: <br>
	<?php foreach ($this->discount_delivery[0]->community as $c):?>
	<?=$c->code?> <?=$c->name?> / 
	<?php endforeach;?>
	!!!</div>
	<?php }?>
	<?php }?>
	</div>
	<div class="rightbar">
<div class="ctn_cart">


<div class="order_info">
<p>Mon Panier</p>
<?php $i = 1; ?>
<?php if(!$this->cart->contents()){?><p>Vous n'avez pas encore choisi les articles...<br><a href="<?=site_url('menu')?>">Compléter votre commande</a></p><?php }?>
<form <?php if(isset($_GET['date'])){?>action="<?=site_url('cart/update?date=reservation')?>"<?php }else{?>action="<?=site_url('cart/update/special')?>"<?php }?> name="update_cart" enctype="multipart/form-data" method="post">
<?php foreach ($this->cart->contents() as $items): ?>
<div class="order_item">
<span class="product_item">
 <?php echo form_hidden($i.'[rowid]', $items['rowid']); ?>
<?=$items['product_num']?>. 
 <?php echo $items['name']; ?>
 </span>
<span class="qty_form">
	<?php echo $this->cart->format_number($items['price']); ?><?php if($items['options_price'] !=NULL && $items['options_price'] != 0){ echo '<span class="option_price">  +'.$items['options_price'].'</span>';}?> € X 
	<select name="<?=$i.'[qty]'?>" onchange="document.update_cart.submit();">
 	<?php if($items['name']=='Table de riz'){$q=4; echo '<option value="0">0</option>';}else{$q=0;} for($q;$q<20;$q++){?> 
 	<option value="<?=$q?>" id="<?=$i.'[qty]'?>"<?php if($items['qty']==$q){echo "selected='selected'";}?> ><?=$q?></option>
 	<?php }?>
 	</select>= <?php echo $this->cart->format_number($items['subtotal'] + $items['options_price']*$items['qty']); ?> €
 	</span><br>
 	<span class="option"><?php if($this->cart->has_options($items['rowid'])==TRUE):?><label><small>OPTIONs:	</small></label><?php foreach ($this->cart->product_options($items['rowid']) as $option): ?><?=nbs(3)?>

					<small><?php echo $option['option_name']; ?> <?php if( $option['price'] !=NULL ){ echo ': '.$option['price'].' €';} ?></small><?=nbs(3)?>

					<?php endforeach; ?><?php endif; ?></span>
 	<div class="clear"></div>
 	
</div>

<?php $i++; ?>

<?php endforeach; ?>
</form>

<br>

<h3>Réduction: <?=$this->discount_delivery[0]->discount_val*100?> %<br></h3>
<div class="total"><span>Total: <?=number_format($this->cart->total()*(1-$this->discount_delivery[0]->discount_val),'1','.','')?> </span></div>
<br>
<div class="clear"></div>
<a href="javascript:void(0)" onclick="empty_cart()">Videz Votre Panier</a>
<div class="clear"></div>
</div>
<br>
<div class="order_type">
<?php if($this->discount_delivery){?>
<div class="special_promo">
A partir du <?=date('d M. Y',strtotime($this->discount_delivery[0]->discount_start))?> jusqu'au <?=date('d M. Y',strtotime($this->discount_delivery[0]->discount_end))?>,  Pour les commandes de livraison, Une Réduction de <?=$this->discount_delivery[0]->discount_val*100?>% 
	pour les communes: <br>
	<?php foreach ($this->discount_delivery[0]->community as $c):?>
	<?=$c->code?> <?=$c->name?> / 
	<?php endforeach;?>
	</div>
<?php }?>

<input type="button" value="Livraison" onclick="choose_com()">
<form action="<?=site_url('cart/delivery')?>" method="post" id="delivery_form">
<div class="community_list">
<div class="error"></div>
<img class="delivery_arrow" src="<?=base_url()?>resources/imgs/down_arrow.png" alt="arrow" title="arrow" width="25">

<div class="styled-select">

<select name="com" id="com">
<option value="null" limit="null">choisissez votre commune...</option>
<?php foreach ($coms as $c):?>
<?php if($c->discount_id == $this->discount_delivery[0]->id){?>
<option value="<?=$c->id?>" com_code="<?=$c->code?>" limit="<?=$c->limit_price?>"> <?=$c->code?> <?=$c->name?></option>
<?php }?>
<?php endforeach;?>
</select>
</div>
<input type="hidden" name="com_name" value="" id="com_name">
<input type="hidden" name="discount_type" value="discount_delivery" id="discount_type">
<input type="hidden" name="exrat" value="0" id="extra">
<input type="button" value="suivant" onclick="delivery_validation()">
<input type="button" value="fermé" onclick="close_choose_com()">
</form>
</div>
</div>

<div class="info_supplement">
<h2>Informations Importantes</h2>
<hr>
<h3>Une commande pour Livraison:</h3>

<?php foreach ($limits as $l):?>
<h3>A partir de <?=$l?> € (après réduction) , pour les communes :</h3>
<p>
 <?php foreach ($coms as $c):?>
 <?php if($c->limit_price == $l){?><?=$c->code?> <?=$c->name?>, <?php }?>
<?php endforeach;?>
</p>
<?php endforeach;?>
<hr>
<p>
<span>Pour toute commande immédiate, prévoyez un délai minimum de 45min.</span><br>

</p>

<p>Commande prise en compte seulement pendant les horaires d'ouverture :</p>
<p>
<?php foreach ($shop as $s):?>
<?=$s->shop_name?>, <?=$s->open_hour?>, <?=$s->open_day?><br>
<?php endforeach;?>
</p>
<p>La dernière commande doit être effectué une demi-heure  avant  la fermeture de magasin.</p>
<p>
<span>Toute commande donnée après l'heure d'ouverture ne sera pas prise en compte pour le soir même.</span>
</p>
</div>
</div>
<div class="clear"></div>
</div></div>